﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaPortal.Profile;
using MediaPortal.Configuration;
using MediaPortal.GUI.Library;
using InfoService.Utils;

namespace InfoService.Utils
{
    public static class RecentlyAddedUtils
    {
        public static void SaveLastRecentlyAddedItems()
        {
            using (Settings settings = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                for (int i = 1; i <= 3; i++)
                {
                    settings.SetValue("InfoService", "RecentlyAddedSeries" + i + "Title", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.series[" + i + "].title"));
                    settings.SetValue("InfoService", "RecentlyAddedSeries" + i + "Season", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.series[" + i + "].season"));
                    settings.SetValue("InfoService", "RecentlyAddedSeries" + i + "Episodenumber", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.series[" + i + "].episodenumber"));
                    settings.SetValue("InfoService", "RecentlyAddedSeries" + i + "Episodetitle", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.series[" + i + "].episodetitle"));
                    settings.SetValue("InfoService", "RecentlyAddedSeries" + i + "Thumb", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.series[" + i + "].thumb"));
                    settings.SetValue("InfoService", "RecentlyAddedSeries" + i + "Fanart", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.series[" + i + "].fanart"));

                    settings.SetValue("InfoService", "RecentlyAddedMovie" + i + "Title", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.movie[" + i + "].title"));
                    settings.SetValue("InfoService", "RecentlyAddedMovie" + i + "Thumb", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.movie[" + i + "].thumb"));
                    settings.SetValue("InfoService", "RecentlyAddedMovie" + i + "Fanart", GUIPropertyManager.GetProperty("#infoservice.recentlyAdded.movie[" + i + "].fanart"));
                }
            }
        }

        public static void LoadLastRecentlyAddedItems()
        {
            using (Settings settings = new Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml")))
            {
                for (int i = 1; i <= 3; i++)
                {
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.series[" + i + "].title", settings.GetValueAsString("InfoService", "RecentlyAddedSeries" + i + "Title", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.series[" + i + "].season", settings.GetValueAsString("InfoService", "RecentlyAddedSeries" + i + "Season", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.series[" + i + "].episodenumber", settings.GetValueAsString("InfoService", "RecentlyAddedSeries" + i + "Episodenumber", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.series[" + i + "].episodetitle", settings.GetValueAsString("InfoService", "RecentlyAddedSeries" + i + "Episodetitle", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.series[" + i + "].thumb", settings.GetValueAsString("InfoService", "RecentlyAddedSeries" + i + "Thumb", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.series[" + i + "].fanart", settings.GetValueAsString("InfoService", "RecentlyAddedSeries" + i + "Fanart", ""));

                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.movie[" + i + "].title", settings.GetValueAsString("InfoService", "RecentlyAddedMovie" + i + "Title", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.movie[" + i + "].thumb", settings.GetValueAsString("InfoService", "RecentlyAddedMovie" + i + "Thumb", ""));
                    InfoServiceUtils.SetProperty("#infoservice.recentlyAdded.movie[" + i + "].fanart", settings.GetValueAsString("InfoService", "RecentlyAddedMovie" + i + "Fanart", ""));
                }
            }
        }
    }
}
